(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, 0), x, y)
cond2(true, x, y) → cond1(gr(add(x, y), 0), p(x), y)
cond2(false, x, y) → cond3(gr(y, 0), x, y)
cond3(true, x, y) → cond1(gr(add(x, y), 0), x, p(y))
cond3(false, x, y) → cond1(gr(add(x, y), 0), x, y)
gr(0, x) → false
gr(s(x), 0) → true
gr(s(x), s(y)) → gr(x, y)
add(0, x) → x
add(s(x), y) → s(add(x, y))
p(0) → 0
p(s(x)) → x

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, 0), x, y) [1]
cond2(true, x, y) → cond1(gr(add(x, y), 0), p(x), y) [1]
cond2(false, x, y) → cond3(gr(y, 0), x, y) [1]
cond3(true, x, y) → cond1(gr(add(x, y), 0), x, p(y)) [1]
cond3(false, x, y) → cond1(gr(add(x, y), 0), x, y) [1]
gr(0, x) → false [1]
gr(s(x), 0) → true [1]
gr(s(x), s(y)) → gr(x, y) [1]
add(0, x) → x [1]
add(s(x), y) → s(add(x, y)) [1]
p(0) → 0 [1]
p(s(x)) → x [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, 0), x, y) [1]
cond2(true, x, y) → cond1(gr(add(x, y), 0), p(x), y) [1]
cond2(false, x, y) → cond3(gr(y, 0), x, y) [1]
cond3(true, x, y) → cond1(gr(add(x, y), 0), x, p(y)) [1]
cond3(false, x, y) → cond1(gr(add(x, y), 0), x, y) [1]
gr(0, x) → false [1]
gr(s(x), 0) → true [1]
gr(s(x), s(y)) → gr(x, y) [1]
add(0, x) → x [1]
add(s(x), y) → s(add(x, y)) [1]
p(0) → 0 [1]
p(s(x)) → x [1]

The TRS has the following type information:
cond1 :: true:false → 0:s → 0:s → cond1:cond2:cond3
true :: true:false
cond2 :: true:false → 0:s → 0:s → cond1:cond2:cond3
gr :: 0:s → 0:s → true:false
0 :: 0:s
add :: 0:s → 0:s → 0:s
p :: 0:s → 0:s
false :: true:false
cond3 :: true:false → 0:s → 0:s → cond1:cond2:cond3
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

cond1(v0, v1, v2) → null_cond1 [0]

And the following fresh constants:

null_cond1

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, 0), x, y) [1]
cond2(true, x, y) → cond1(gr(add(x, y), 0), p(x), y) [1]
cond2(false, x, y) → cond3(gr(y, 0), x, y) [1]
cond3(true, x, y) → cond1(gr(add(x, y), 0), x, p(y)) [1]
cond3(false, x, y) → cond1(gr(add(x, y), 0), x, y) [1]
gr(0, x) → false [1]
gr(s(x), 0) → true [1]
gr(s(x), s(y)) → gr(x, y) [1]
add(0, x) → x [1]
add(s(x), y) → s(add(x, y)) [1]
p(0) → 0 [1]
p(s(x)) → x [1]
cond1(v0, v1, v2) → null_cond1 [0]

The TRS has the following type information:
cond1 :: true:false → 0:s → 0:s → null_cond1
true :: true:false
cond2 :: true:false → 0:s → 0:s → null_cond1
gr :: 0:s → 0:s → true:false
0 :: 0:s
add :: 0:s → 0:s → 0:s
p :: 0:s → 0:s
false :: true:false
cond3 :: true:false → 0:s → 0:s → null_cond1
s :: 0:s → 0:s
null_cond1 :: null_cond1

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

true => 1
0 => 0
false => 0
null_cond1 => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

add(z, z') -{ 1 }→ x :|: z' = x, x >= 0, z = 0
add(z, z') -{ 1 }→ 1 + add(x, y) :|: x >= 0, y >= 0, z = 1 + x, z' = y
cond1(z, z', z'') -{ 1 }→ cond2(gr(x, 0), x, y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond1(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
cond2(z, z', z'') -{ 1 }→ cond3(gr(y, 0), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
cond2(z, z', z'') -{ 1 }→ cond1(gr(add(x, y), 0), p(x), y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond3(z, z', z'') -{ 1 }→ cond1(gr(add(x, y), 0), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
cond3(z, z', z'') -{ 1 }→ cond1(gr(add(x, y), 0), x, p(y)) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
gr(z, z') -{ 1 }→ gr(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
gr(z, z') -{ 1 }→ 1 :|: x >= 0, z = 1 + x, z' = 0
gr(z, z') -{ 1 }→ 0 :|: z' = x, x >= 0, z = 0
p(z) -{ 1 }→ x :|: x >= 0, z = 1 + x
p(z) -{ 1 }→ 0 :|: z = 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V2),0,[cond1(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[cond2(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[cond3(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[gr(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[add(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[p(V, Out)],[V >= 0]).
eq(cond1(V, V1, V2, Out),1,[gr(V3, 0, Ret0),cond2(Ret0, V3, V4, Ret)],[Out = Ret,V1 = V3,V2 = V4,V = 1,V3 >= 0,V4 >= 0]).
eq(cond2(V, V1, V2, Out),1,[add(V5, V6, Ret00),gr(Ret00, 0, Ret01),p(V5, Ret1),cond1(Ret01, Ret1, V6, Ret2)],[Out = Ret2,V1 = V5,V2 = V6,V = 1,V5 >= 0,V6 >= 0]).
eq(cond2(V, V1, V2, Out),1,[gr(V7, 0, Ret02),cond3(Ret02, V8, V7, Ret3)],[Out = Ret3,V1 = V8,V2 = V7,V8 >= 0,V7 >= 0,V = 0]).
eq(cond3(V, V1, V2, Out),1,[add(V9, V10, Ret001),gr(Ret001, 0, Ret03),p(V10, Ret21),cond1(Ret03, V9, Ret21, Ret4)],[Out = Ret4,V1 = V9,V2 = V10,V = 1,V9 >= 0,V10 >= 0]).
eq(cond3(V, V1, V2, Out),1,[add(V11, V12, Ret002),gr(Ret002, 0, Ret04),cond1(Ret04, V11, V12, Ret5)],[Out = Ret5,V1 = V11,V2 = V12,V11 >= 0,V12 >= 0,V = 0]).
eq(gr(V, V1, Out),1,[],[Out = 0,V1 = V13,V13 >= 0,V = 0]).
eq(gr(V, V1, Out),1,[],[Out = 1,V14 >= 0,V = 1 + V14,V1 = 0]).
eq(gr(V, V1, Out),1,[gr(V15, V16, Ret6)],[Out = Ret6,V1 = 1 + V16,V15 >= 0,V16 >= 0,V = 1 + V15]).
eq(add(V, V1, Out),1,[],[Out = V17,V1 = V17,V17 >= 0,V = 0]).
eq(add(V, V1, Out),1,[add(V18, V19, Ret11)],[Out = 1 + Ret11,V18 >= 0,V19 >= 0,V = 1 + V18,V1 = V19]).
eq(p(V, Out),1,[],[Out = 0,V = 0]).
eq(p(V, Out),1,[],[Out = V20,V20 >= 0,V = 1 + V20]).
eq(cond1(V, V1, V2, Out),0,[],[Out = 0,V21 >= 0,V2 = V22,V23 >= 0,V = V21,V1 = V23,V22 >= 0]).
input_output_vars(cond1(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(cond2(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(cond3(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(gr(V,V1,Out),[V,V1],[Out]).
input_output_vars(add(V,V1,Out),[V,V1],[Out]).
input_output_vars(p(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [add/3]
1. recursive : [gr/3]
2. non_recursive : [p/2]
3. recursive : [cond1/4,cond2/4,cond3/4]
4. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into add/3
1. SCC is partially evaluated into gr/3
2. SCC is partially evaluated into p/2
3. SCC is partially evaluated into cond1/4
4. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations add/3
* CE 12 is refined into CE [22]
* CE 11 is refined into CE [23]


### Cost equations --> "Loop" of add/3
* CEs [23] --> Loop 13
* CEs [22] --> Loop 14

### Ranking functions of CR add(V,V1,Out)
* RF of phase [14]: [V]

#### Partial ranking functions of CR add(V,V1,Out)
* Partial RF of phase [14]:
- RF of loop [14:1]:
V


### Specialization of cost equations gr/3
* CE 15 is refined into CE [24]
* CE 14 is refined into CE [25]
* CE 13 is refined into CE [26]


### Cost equations --> "Loop" of gr/3
* CEs [25] --> Loop 15
* CEs [26] --> Loop 16
* CEs [24] --> Loop 17

### Ranking functions of CR gr(V,V1,Out)
* RF of phase [17]: [V,V1]

#### Partial ranking functions of CR gr(V,V1,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V
V1


### Specialization of cost equations p/2
* CE 17 is refined into CE [27]
* CE 16 is refined into CE [28]


### Cost equations --> "Loop" of p/2
* CEs [27] --> Loop 18
* CEs [28] --> Loop 19

### Ranking functions of CR p(V,Out)

#### Partial ranking functions of CR p(V,Out)


### Specialization of cost equations cond1/4
* CE 21 is refined into CE [29]
* CE 18 is refined into CE [30]
* CE 19 is refined into CE [31]
* CE 20 is refined into CE [32]


### Cost equations --> "Loop" of cond1/4
* CEs [30] --> Loop 20
* CEs [31] --> Loop 21
* CEs [32] --> Loop 22
* CEs [29] --> Loop 23

### Ranking functions of CR cond1(V,V1,V2,Out)
* RF of phase [20]: [V1]
* RF of phase [21]: [V2]

#### Partial ranking functions of CR cond1(V,V1,V2,Out)
* Partial RF of phase [20]:
- RF of loop [20:1]:
V1
* Partial RF of phase [21]:
- RF of loop [21:1]:
V2


### Specialization of cost equations start/3
* CE 2 is refined into CE [33,34,35,36,37,38]
* CE 6 is refined into CE [39,40,41,42,43,44,45]
* CE 3 is refined into CE [46,47,48,49]
* CE 4 is refined into CE [50,51,52]
* CE 5 is refined into CE [53,54,55,56,57]
* CE 7 is refined into CE [58,59,60]
* CE 8 is refined into CE [61,62,63,64]
* CE 9 is refined into CE [65,66]
* CE 10 is refined into CE [67,68]


### Cost equations --> "Loop" of start/3
* CEs [42,43] --> Loop 24
* CEs [36,37,38,44,45,60] --> Loop 25
* CEs [34,35,40,41,58,59] --> Loop 26
* CEs [33,39,62,63,64,66,68] --> Loop 27
* CEs [46,47,48,49,50,51,52,53,54,55,56,57,61,65,67] --> Loop 28

### Ranking functions of CR start(V,V1,V2)

#### Partial ranking functions of CR start(V,V1,V2)


Computing Bounds
=====================================

#### Cost of chains of add(V,V1,Out):
* Chain [[14],13]: 1*it(14)+1
Such that:it(14) =< -V1+Out

with precondition: [V+V1=Out,V>=1,V1>=0]

* Chain [13]: 1
with precondition: [V=0,V1=Out,V1>=0]


#### Cost of chains of gr(V,V1,Out):
* Chain [[17],16]: 1*it(17)+1
Such that:it(17) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[17],15]: 1*it(17)+1
Such that:it(17) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [16]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [15]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of p(V,Out):
* Chain [19]: 1
with precondition: [V=0,Out=0]

* Chain [18]: 1
with precondition: [V=Out+1,V>=1]


#### Cost of chains of cond1(V,V1,V2,Out):
* Chain [[21],23]: 8*it(21)+0
Such that:it(21) =< V2

with precondition: [V=1,V1=0,Out=0,V2>=1]

* Chain [[21],22,23]: 8*it(21)+7
Such that:it(21) =< V2

with precondition: [V=1,V1=0,Out=0,V2>=1]

* Chain [[20],[21],23]: 6*it(20)+8*it(21)+1*s(3)+0
Such that:it(21) =< V2
aux(3) =< V1
it(20) =< aux(3)
s(3) =< it(20)*aux(3)

with precondition: [V=1,Out=0,V1>=1,V2>=1]

* Chain [[20],[21],22,23]: 6*it(20)+8*it(21)+1*s(3)+7
Such that:it(21) =< V2
aux(4) =< V1
it(20) =< aux(4)
s(3) =< it(20)*aux(4)

with precondition: [V=1,Out=0,V1>=1,V2>=1]

* Chain [[20],23]: 6*it(20)+1*s(3)+0
Such that:aux(5) =< V1
it(20) =< aux(5)
s(3) =< it(20)*aux(5)

with precondition: [V=1,Out=0,V1>=1,V2>=0]

* Chain [[20],22,23]: 6*it(20)+1*s(3)+7
Such that:aux(6) =< V1
it(20) =< aux(6)
s(3) =< it(20)*aux(6)

with precondition: [V=1,V2=0,Out=0,V1>=1]

* Chain [23]: 0
with precondition: [Out=0,V>=0,V1>=0,V2>=0]

* Chain [22,23]: 7
with precondition: [V=1,V1=0,V2=0,Out=0]


#### Cost of chains of start(V,V1,V2):
* Chain [28]: 64*s(21)+78*s(22)+12*s(28)+13
Such that:aux(13) =< V1
aux(14) =< V2
s(22) =< aux(13)
s(28) =< s(22)*aux(13)
s(21) =< aux(14)

with precondition: [V=0]

* Chain [27]: 2*s(45)+1*s(46)+11
Such that:s(46) =< V1
aux(15) =< V
s(45) =< aux(15)

with precondition: [V>=1]

* Chain [26]: 48*s(49)+11
Such that:aux(16) =< V2
s(49) =< aux(16)

with precondition: [V>=0,V1>=0,V2>=0]

* Chain [25]: 76*s(54)+1*s(55)+64*s(57)+12*s(63)+11
Such that:s(55) =< 1
aux(19) =< V1
aux(20) =< V2
s(54) =< aux(19)
s(57) =< aux(20)
s(63) =< s(54)*aux(19)

with precondition: [V=1,V1>=1,V2>=0]

* Chain [24]: 26*s(76)+4*s(82)+11
Such that:aux(22) =< V1
s(76) =< aux(22)
s(82) =< s(76)*aux(22)

with precondition: [V=1,V2=0,V1>=1]


Closed-form bounds of start(V,V1,V2):
-------------------------------------
* Chain [28] with precondition: [V=0]
- Upper bound: nat(V1)*78+13+nat(V1)*12*nat(V1)+nat(V2)*64
- Complexity: n^2
* Chain [27] with precondition: [V>=1]
- Upper bound: 2*V+11+nat(V1)
- Complexity: n
* Chain [26] with precondition: [V>=0,V1>=0,V2>=0]
- Upper bound: 48*V2+11
- Complexity: n
* Chain [25] with precondition: [V=1,V1>=1,V2>=0]
- Upper bound: 76*V1+12+12*V1*V1+64*V2
- Complexity: n^2
* Chain [24] with precondition: [V=1,V2=0,V1>=1]
- Upper bound: 26*V1+11+4*V1*V1
- Complexity: n^2

### Maximum cost of start(V,V1,V2): max([nat(V2)*48,nat(V1)+max([2*V,nat(V1)*50+1+nat(V1)*8*nat(V1)+nat(V2)*64+ (nat(V1)*2+1)+ (nat(V1)*4*nat(V1)+nat(V1)*25)])])+11
Asymptotic class: n^2
* Total analysis performed in 552 ms.

(10) BOUNDS(1, n^2)